package cn.tradewin.advisor.pages.tasks;

 import java.util.Map;

import org.activiti.engine.TaskService;
import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;

public class DealHandleRequest {

	@Inject
	Logger log;
	
	private String taskId;
	
	@Property
	@Persist(PersistenceConstants.FLASH)
	private String vacationApproved;
	
	@Property
	private String note;
	
	@Inject
	private TaskService taskService;
	
	@OnEvent(EventConstants.ACTIVATE)
	void onActive(String taskId) {
		this.taskId = taskId;
	}
	
	String onPassivate() {
		return this.taskId;
	}
	
	void onSubmit() {
		Map<String, Object> variables = CollectionFactory.newMap();
		variables.put("vacationApproved", vacationApproved);
		variables.put("numberOfDays", 3);
		variables.put("managerMotivation", note);
		taskService.complete(taskId, variables);
	}
}
